<?php

class Admin

{
 
		 /*function to check if the login is valid */
	                   
	            function is_loginValid( $username, $password ){	
		          global $ado;
		          $password = md5($password);
		          $sql = "SELECT * FROM  `admin` WHERE `username`  = '$username' and `password` = '$password' and `status` = '1' LIMIT 1 "; 	             $res = $ado->exec($sql);
		          if($ado->count($res) >0)
		          {	
		          $user_details = $ado->fetch($res);
			  return($user_details);			
			  } else {
		          return -1;
		                 }
	                   }
	            /*end function */ 
	            
	            /*function to see if the admin is logged in */
	            
	             function isAdminLoggedIn(){		
		          if(isset($_SESSION['admin']) ){
			  return 1;	
		          } else {
			  return 0;
		             }		
	                  }
	                  
	            /*end function*/
	            
	            /*function to logout the admin*/
	            
	             function logout(){	
		           if(isset($_SESSION['admin'])){ 	 
			   session_unset(); 
			   session_destroy();  
		           } else {
			  session_start();
			  session_unset(); 
			  session_destroy();  
		          }
		          }
		          
		   /*end function*/
		   
		   /*function to update site settings*/
		   
		    function updateSettings($post_array){
			
			$site_title = clean($post_array['site_title']);
			$site_email = clean($post_array['site_email']);
			$meta_keywords = clean($post_array['meta_keywords']);
			$meta_description = clean($post_array['meta_description']);
			$upload_path = clean($post_array['upload_path']);
			$payment_threshold = clean($post_array['payment_threshold']);
			if(!file_exists($upload_path)) { 
                        mkdir($upload_path); 
                        chmod($uploadpath, 0777);
                        }
			$sql = "UPDATE `settings` SET `site_title` = '$site_title', `site_email` = '$site_email', 
			`meta_keywords` = '$meta_keywords', `meta_description` = '$meta_description', `upload_path` = '$upload_path', `payment_threshold`='$payment_threshold'"; 
			
			if(mysql_query($sql)){
			return 1;
		        } 
			else {
			       return -1;
	                }	
	                }
	                /*end function */
	                
	                 /*function to update site settings*/
		   
		    function updateEarningPercent($post_array){
			
			$referral = clean($post_array['referral']);
			$normal = clean($post_array['normal']);
			
			$sql = "UPDATE `settings` SET `referral_percent` = '$referral', `user_percent` = '$normal'"; 
			
			if(mysql_query($sql)){
			return 1;
		        } 
			else {
			       return -1;
	                }	
	                }
	                /*end function */
	                
	                /*function to get admin email*/
	                
	                function getAdminEmail(){
		        global $ado;
		        $sql ="SELECT `email` FROM `admin` LIMIT 1";
		        $res = $ado->exec($sql);
		        $ret = $ado->fetch($res);			
		        return $ret['email'];		
		        }
	                
	                /*end function*/
	                
	                 /*function to update gateway settings*/
	                  
	                 function updateGateway($post_array){
			
			$publisher = clean($post_array['publisher']);
			$gateway = clean($post_array['gateway']);
			$password = clean($post_array['password']);
			$network = clean($post_array['network']);
			
			$sql = "UPDATE `gateway` SET `gateway_id` = '$gateway', `publisher_id` = '$publisher', `network` = '$network', `password` = '$password'"; 
			
			if(mysql_query($sql)){
			       return 1;
		        } 
			else {
			       return -1;
	                }	
	                }
	                /*end function */
	              
}

global $admin;

$admin = new Admin();

?>